<template>
  <div>
    <div v-if="!pushStatus">
    <el-row style="margin-bottom:10px">
      <el-col :span="8" >
        <h4 style="margin:0">
          <span>医院列表</span>
          <el-button  type="success" class="addBtn" v-if="userRole.HPT_ID_1701001" @click="addUserFun"><i class="el-icon-plus"></i>账号</el-button>          
        </h4>
      </el-col>
      <el-col :span="16" style="text-align:right">
        <el-select  v-model="city" clearable placeholder="选择省份" style="width:130px" @change="changeCity">
            <el-option v-for="item in oders" :key="item.value" :label="item.areaname" :value="item.id"></el-option>
        </el-select>
         <el-select  v-model="cityVal"  clearable placeholder="请选择城市" style="width:130px">
            <el-option v-for="item in citys" :key="item.value" :label="item.areaname" :value="item.id"></el-option>
        </el-select>
       <el-select  v-model="selectStatus"  placeholder="请选择" style="width:100px">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
        <el-input v-model="keyword" style="width:300px" placeholder="输入昵称"></el-input>
        <el-button type="primary" @click="sheachFun">搜索</el-button>
      </el-col>
    </el-row>
   
    <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55"></el-table-column>-->
      <el-table-column prop="ID" label="序号" width="60">
         <template slot-scope="scope">{{scope.$index+1}}</template>
      </el-table-column>
      <el-table-column prop="city" label="城市"> </el-table-column>      
      <el-table-column prop="name" label="名称"></el-table-column>
      <el-table-column prop="account_name" label="账号"></el-table-column>
      <el-table-column prop="bindTel" label="绑定手机"></el-table-column>
      <el-table-column prop="business_time" label="营业时间"></el-table-column>
      <el-table-column prop="tel" label="联系电话"></el-table-column>
      <el-table-column prop="doctor_count" label="医生数"></el-table-column>
      <el-table-column prop="is_auth" label="是否认证"></el-table-column>
      <el-table-column prop="tui" label="审核状态">
        <template  slot-scope="scope">
          <span  v-if="scope.row.status==0">未审核</span>
          <span style="color:#67c23a" v-else-if="scope.row.status==1">上线</span>
          <span style="color:red" v-else>下线</span>
          <span style="color:#67c23a" v-if="scope.row.order_at">置顶</span>
        </template>
      </el-table-column>
      <el-table-column prop="tui" label="状态">
        <template  slot-scope="scope">
          <span  v-if="scope.row.status==0">未审核</span>
          <span style="color:#67c23a" v-else-if="scope.row.status==1">上线</span>
          <span style="color:red" v-else>下线</span>
          <span style="color:#67c23a" v-if="scope.row.order_at">置顶</span>
        </template>
      </el-table-column>
      <el-table-column width="220" label="操作">
        <template slot-scope="scope">
          <div>
            <el-button class="addBtn"  v-if="userRole.HPT_ID_1701001" @click="seachFun(scope.row)">查看</el-button>
            <span v-if="userRole.HPT_ID_1701002">
              <el-button v-if="!scope.row.order_at && scope.row.status > 0" type="primary" class="addBtn" @click="stickFun(scope.row.hospital_id)">置顶</el-button>
              <el-button v-if=" scope.row.order_at"  class="addBtn" @click="upStickFun(scope.row.hospital_id)">取消置顶</el-button>
              <el-button class="addBtn" type="warning" v-if="scope.row.status==1" @click="disabelFun(scope.row.hospital_id)">下线</el-button>
              <el-button class="addBtn" type="success" v-else-if="scope.row.status==2" @click="startFun(scope.row.hospital_id)">上线</el-button>
              <el-button class="addBtn" type="danger"  @click="deleteFun(scope.row.hospital_id)">删除</el-button>
            </span>
          </div>
        </template>
      </el-table-column>
    </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
   
    <div v-if="pushStatus">
       <Add-hospital @colseFun="colseFun" :editVal="editVal"></Add-hospital>
    </div>
  </div>
</template>

<script>
  import AddHospital from './Hositem/AddHospital'
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'
  export default {
    data() {
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        editVal:'',
        pushStatus:false,
        dialogVisible:false,
        dataPush:'',
        total:0,
        currentPage4: 1,//分野  
        page:1,
        pageSize:10,
        tableData: [],
        keyword:'',
        selectStatus:-1,
        city:'',
        cityVal:'',
        oders:[],
        citys:[],
        options:[
          {
            label:'全部',
            value:-1,
          },
          {
            label:'上线',
            value:1,
          },
          {
            label:'下线',
            value:2
          }
        ],
      }
    },
    components:{
      AddHospital
    },
    created(){
      
      this.getlist()
    },
    methods: {
      getlist(){
        const obj = {
          "pageIndex":this.page,
          "pageSize":this.pageSize
        };
        
        if(this.keyword){
          obj.keyword = this.keyword;
        }
        if(this.selectStatus != -1){
          obj.status = this.selectStatus
        };
        if(this.cityVal){
          obj.cityId = this.cityVal
        }
        Http.getIdentifyListlist(obj)
        .then( res => {
          this.tableData = res.data.data.rows;
          this.total = res.data.data.total;
          this.pushStatus = false
        })
        .catch( error => {
          
        })
        Http.getAreaList(0)
        .then( res => {
          this.oders = res.data.data;
        })
      },
      getdata (evt) {
      },
      sheachFun(){
        this.page = 1;
        this.getlist()
      },
      deleteFun(row){
        
        this.$confirm('确定删除此医院吗？','提示',{
          confirmVuttonText:'确定',
          confirmButtonText:'确定'
        }).then( ()=> {
          Http.deleteHospita(row)
          .then( res => {
            if ( res.data.code == 200 ){
              this.$message.success(`删除成功`)
              this.getlist()
            } else if (res.data.code == -1003) {
                this.$message.error(`token过期，请重新登录`)
                this.$router.push('/')
            } else {
              this.$message.error('操作失败')
            }
        }).catch( ()=> {
          
        })
    
        
        })
        .catch( error => {
          
        })
      },
      colseFun(){
        this.pushStatus = false;
        this.getlist()
      },
     //获取地址部分
    changeCity(val,city=''){
      this.okLng = 0;
      Http.getAreaList(val)
        .then( res => {
          this.cityVal = '';
          this.citys = res.data.data;
          
        })
    },
      //添加用户
      addUserFun() {
        this.editVal = '';
        this.pushStatus = true;
      },
      seachFun(row){
        this.pushStatus = true;
        this.editVal = row;
        
      },
      stickFun(row) {
        Http.stickHospital(row)
        .then( res => {
          if ( res.data.code == 200 ){
            this.$message.success(`取消置顶`)
            this.getlist()
          } else if (res.data.code == -1003) {
              this.$message.error(`token过期，请重新登录`)
              this.$router.push('/')
          } else {
            this.$message.error('操作失败')
          }
        })
      },
      upStickFun(row){
        Http.unStickHospital(row)
        .then( res => {
          if ( res.data.code == 200 ){
            this.$message.success(`置顶成功`)
            this.getlist()
          } else if (res.data.code == -1003) {
              this.$message.error(`token过期，请重新登录`)
              this.$router.push('/')
          } else {
            this.$message.error('操作失败')
          }
        })
      },
      startFun(row) {
        Http.startAdmin(row)
        .then( res => {
          if ( res.data.code == 200 ){
            this.$message.success(`启用成功`)
            this.getlist()
          } else if (res.data.code == -1003) {
              this.$message.error(`token过期，请重新登录`)
              this.$router.push('/')
          } else {
            this.$message.error('操作失败')
          }
        })
      },
      //禁用 账号
      disabelFun(row){
        Http.disableAdmin(row)
        .then( res => {
          if ( res.data.code == 200 ){
            this.$message.success(`禁用成功`)
            this.getlist()
          } else if (res.data.code == -1003) {
              this.$message.error(`token过期，请重新登录`)
              this.$router.push('/')
          } else {
            this.$message.error('操作失败')
          }
        })
      },
      //选择 推荐
      handleSelectionChange() {
        
      },
         //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getlist()
        
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getlist()
        
      },
    }
  }
</script>
<style  scoped>
.box{
  border-bottom:1px solid red;
}
    .test{
        border:1px solid #ccc;
    }
    .drag-item{
        width: 200px;
        height: 50px;
        line-height: 50px;
        margin: auto;
        position: relative;
        
        background: #ddd;
        margin:20px 5px;
    }
    .ghostClass{
        opacity: 1;
    }
    .bottom{
        width: 200px;
        height: 50px;
        position: relative;
        background: blue;
        top:2px;
        left: 2px;
        transition: all .5s linear;
    }
</style>
